// ml:run = $bin < A-large.in > A-small.out
#include <iostream>

using ll = long long;

ll const inf = (1ll) << 48;
int const maxn = 2007;
ll dp[maxn][maxn];
ll s[maxn];
ll f[maxn];
ll d[maxn];
ll n, ts, tf;

void init()
{
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = inf;
}

ll calc(ll tmp, int i)
{
    if (tmp >= inf) return inf;
    // si + x fi >= tmp
    //     x >= (tmp - si) / fi
    auto t = tmp - s[i];
    auto x = (t + f[i] - 1) / f[i];
    x = std::max(x, 0ll);
    return s[i] + x * f[i] + d[i];
}

int main()
{
    std::ios::sync_with_stdio(false);
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        std::cin >> n >> ts >> tf;
        for (int i = 1; i <= n - 1; i++)
            std::cin >> s[i] >> f[i] >> d[i];

        init();

        dp[1][0] = 0;
        dp[1][1] = ts;
        for (int i = 2; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                dp[i][j] = calc(dp[i - 1][j], i - 1);
                if (j >= 1 && i != n) {
                    auto tmp = dp[i - 1][j - 1];
                    dp[i][j] = std::min(dp[i][j], calc(tmp, i - 1) + ts);
                }
            }
        }
        int ans = -1;
        for (int i = 0; i <= n - 1; i++)
            if (dp[n][i] <= tf) ans = i;
        if (ans == -1)
            std::cout << "IMPOSSIBLE\n";
        else
            std::cout << ans << "\n";
    }
}

